
#include <FreeTDS/sybfront.h>
#include <FreeTDS/sybdb.h>
#include "wm_MSSqlResult.h"
#include "wm_MSSqlRow.h"
#include <vector>

namespace worm
{

wmMSSqlResult::wmMSSqlResult(void* const pResult) : CDbResult()
{
    DBPROCESS* pDb = (DBPROCESS*)pResult;
    DBINT nRetCode = dbresults(pDb);

    if (NO_MORE_RESULTS == nRetCode)
    {
        return;
    }

    std::vector<CDbRow*> aRow;
    m_dwFieldCount = dbnumcols(pDb);
    uint32 i = 0;

    wmMSSqlRow* pRow = NULL;
    for (; NO_MORE_RESULTS!=nRetCode;)
    {
        for(;;)
        {
            pRow = new wmMSSqlRow(m_dwFieldCount, pDb);
            nRetCode = dbnextrow(pDb);
            if (NO_MORE_ROWS == nRetCode)
            {
                delete pRow;
                break;
            }
            aRow.push_back(pRow);
            ++m_dwRowCount;
        }
        
        dbhasretstat(pDb);
        nRetCode = dbresults(pDb);
    }

    if (0 != m_dwRowCount)
    {
        m_ppRow = new CDbRow*[m_dwRowCount];
        for (i=0; i!=m_dwRowCount; ++i)
        {
            m_ppRow[i] = aRow[i];
        }
    }

    
}

wmMSSqlResult::~wmMSSqlResult()
{

}

}
